package com.bestcem.xm.om.dao.impl;

import cn.hutool.core.lang.ObjectId;
import com.bestcem.xm.om.dao.OmUserOperateLogDao;
import com.bestcem.xm.om.dao.mapper.OmUserOperateLogMapper;
import com.bestcem.xm.om.entity.OmUserOperateLog;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;

/**
 * @author zhangfeng <feng.zhang@idiaoyan.com>
 * @version v1.0
 * @date 2022/6/22 14:48
 */
@Repository
public class OmUserOperateLogDaoImpl implements OmUserOperateLogDao {
    @Resource
    private OmUserOperateLogMapper omUserOperateLogMapper;

    @Override
    public String insert(OmUserOperateLog userOperateLog) {
        String id = ObjectId.next();
        userOperateLog.setId(id);
        userOperateLog.setCreateTime(LocalDateTime.now());
        userOperateLog.setUpdateTime(Optional.ofNullable(userOperateLog.getUpdateTime()).orElse(LocalDateTime.now()));
        omUserOperateLogMapper.insert(userOperateLog);
        return id;
    }

    @Override
    public int count(OmUserOperateLog userOperateLog) {
        return omUserOperateLogMapper.count(userOperateLog);
    }

    @Override
    public List<OmUserOperateLog> list(OmUserOperateLog operateLog, Integer start, Integer size) {
        return omUserOperateLogMapper.list(operateLog, start, size);
    }
}
